﻿#include "savelogthread.h"
#include "cglobals.h"

SaveLogThread::SaveLogThread(QObject *parent) : QThread(parent)
{

}

SaveLogThread::~SaveLogThread()
{
    delete pReceivedData;
}

// 线程处理函数
void SaveLogThread::run()
{
    QFile logfile(filePath);
    logfile.open(QIODevice::WriteOnly);
    QDataStream out(&logfile);

    if(pReceivedData == NULL) return;

    for(int i = 0; i < pReceivedData->count(); ++i)
    {
#ifdef BASE64
        out<<pReceivedData->at(i)->toHex().toBase64();
#endif

#ifdef HEXDATA
        out<<pReceivedData->at(i)->toHex();
#endif

#ifdef RAWDATA
        out<<*pReceivedData->at(i);
#endif
    }

    logfile.close();

    if(pReceivedData)
    {
        qDeleteAll(pReceivedData->begin(), pReceivedData->end());
        pReceivedData->clear();
    }

    emit savefinished();

    return;
}


void SaveLogThread::setSave(QString filePath, QVector<QByteArray*>* pReceivedData)
{
    this->filePath = filePath;
    this->pReceivedData = pReceivedData;

    return;
}



